<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="https://www.thymeleaf.org">
<head>
    <title>Spring Security OAuth 2.0 Sample</title>
    <meta charset="utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/webjars/bootstrap/css/bootstrap.css"
          th:href="@{/webjars/bootstrap/css/bootstrap.css}"/>
</head>
<body>
<div class="container">
    <h1>Oauth密码模式登录</h1>
    <p th:if="${loginError}" style="font-weight:bold;color:red;">Wrong username or password</p>
    <div class="form-row">
        <div class="form-group">
            <label for="username">Username</label>
            <input type="text" id="username" name="username" autofocus="autofocus" class="form-control">
            <small class="form-text text-muted">user1 / password</small>
        </div>
    </div>
    <div class="form-row">
        <div class="form-group">
            <label for="password">Password</label>
            <input type="password" id="password" name="password" class="form-control">
        </div>
    </div>
    <button id="login" class="btn btn-primary">Log in</button>
</div>
<script src="//cdn.bootcss.com/jquery/1.12.4/jquery.js"></script>
<script src="//cdn.bootcss.com/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>
<script src="/webjars/bootstrap/js/bootstrap.min.js" th:src="@{/webjars/bootstrap/js/bootstrap.min.js}"></script>
<script>
    var token = $.cookie('access_token');
    if (token && token != '' && token != undefined && token != 'undefined') {
        window.location.href = "http://localhost:6090/home";
    } else {
        window.location.href = "http://localhost:6001/oauth/authorize?client_id=admin&redirect_uri=http://localhost:6090/oauth/callback&response_type=code" +
            "&scope=write&state=71d09b58-2a73-4f4f-bdbb-c29becbeddbd#wechat_redirect"
    }
</script>
</body>
</html>